<!DOCTYPE html>
<title>Clicking on the overflow fullscreen button opens the video in fullscreen.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/run-after-layout-and-paint.js"></script>
<script src="media-controls.js"></script>
<script src="overflow-menu.js"></script>

<!--Padding ensures the overflow menu is visible for the tests. -->
<body style="padding-top: 200px; padding-left: 100px">
<video controls controlsList="noplaybackrate" disablePictureInPicture></video>
<script>
async_test(function(t) {
  // Set up video
  var video = document.querySelector("video");
  video.src = "content/test.ogv";
  video.setAttribute("width", "60");
  video.setAttribute("height", "100");

  enableTestMode(video);

  window.addEventListener("load", t.step_func(function() {
    var overflowList = getOverflowList(video);
    var overflowMenu = getOverflowMenuButton(video);

    // Click on the overflow menu button
    var coords = elementCoordinates(overflowMenu);
    clickAtCoordinates(coords[0], coords[1]);

    // Clicking on the fullscreen button should open up the video in fullscreen
    var coords = elementCoordinates(overflowList.children[OverflowMenuButtons.FULLSCREEN]);
    clickAtCoordinates(coords[0], coords[1]);

    document.onwebkitfullscreenchange = t.step_func(() => {
      assert_equals(document.fullscreenElement, video);
      // Hiding the overflow menu is triggered by layout.
      runAfterLayoutAndPaint(t.step_func_done(() => {
        assert_equals(getComputedStyle(overflowMenu).display, "none");
      }));
    });
  }));
});
</script>
</body>
